package com.spzx.product;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import lombok.RequiredArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * Package: com.spzx.product
 *
 * @Description: 商品模块
 * @Author xiongkunYang
 * @Create 2025/5/26 17:52
 */

@EnableCustomConfig
@EnableRyFeignClients
@MapperScan({"com.spzx.product.mapper"})
@SpringBootApplication
@RequiredArgsConstructor
public class SpzxProductApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpzxProductApplication.class, args);
    }

    private final RedisTemplate<Object, Object> redisTemplate;

    private final ProductSkuMapper productSkuMapper;

    //Springboot应用初始化后会执行一次该方法
    @Override
    public void run(String... args) {

        //通过queryWrapper的组装吗，只获取ProductSku中的skuId列表
        LambdaQueryWrapper<ProductSku> queryWrapper = new LambdaQueryWrapper<ProductSku>()
                .eq(ProductSku::getStatus, 1)
                .select(ProductSku::getId);
        List<ProductSku> productSkuIdList = productSkuMapper.selectList(queryWrapper);
        String key = "product:sku:data";
        productSkuIdList.forEach(item -> {
            //为了测试，添加到redis里面
            redisTemplate.opsForValue().setBit(key, item.getId(), true);
        });
    }
}